package view;

import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Model;

/**
 * UserPageDiscoverDiv implements the Discovery Div of a user's signed-in
 * dashboard, populating it with Lithub user book information which can be used
 * by a user to find books in the Lithub database.
 *
 * Primarily used for the web-based side of the Lithub project.
 * 
 * @author Reynaldo Gonzales.
 * @version 1.0
 *
 */
class UserPageDiscoverDiv extends View {

    private Model model;
    private HttpServletRequest request;
    private HttpServletResponse response;

    /**
     * UserPageDiscoverDiv(...) is a reciever of user dashboard page view
     * requests for the Discovery Div and also the responder to such as well.
     *
     * @param a HttpServletRequest request which holds the HTTP request
     * information of the requesting user.
     *
     * @param b HttpServletResponse response to the requesting user.
     *
     */
    UserPageDiscoverDiv(HttpServletRequest req, HttpServletResponse res) {
        request = req;
        response = res;
    }

    /**
     * invoke(modem m) is a model invoker which casts the invokation of the
     * SearchPage/Discovery page model implementation to try to provide a user
     * with valid Lithub database book information.
     *
     * @param a model which refers to the model that implements the
     * UserPageDiscoverDiv.
     *
     * @catch generic exception.
     *
     */
    @Override
    public void invoke(Model m) {
        PrintWriter out = null;
        try {
            request.setAttribute("model", m);
            out = response.getWriter();
            RequestDispatcher view = request.getRequestDispatcher("discover.jsp");
            view.forward(request, response);
        } catch (Exception ex) {
            Logger.getLogger(FrontPageHTML.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
